home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / PROGRAMMING / DESKLIBC / SOURCES.ZIP / DeskLib / !DLSources / Libraries / Icon / c / SetCaret < prev    next >
Text File  |  1995-07-08  |  1KB  |  52 lines

  1. #include "DeskLib:Wimp.h"
  2. #include "DeskLib:WimpSWIs.h"
  3. #include "DeskLib:Icon.h"
  4.  
  5.  
  6. extern void Icon_SetCaret(window_handle window, icon_handle icon)
  7. /*
  8.  * This routine sets the caret within the requested icon. It places the
  9.  * caret at the (righthand) end of the text in the icon. If the icon is not
  10.  * a text icon, then the function returns quietly
  11.  */
  12. {
  13.   caret_block caret;
  14.  
  15.   caret.window = window;
  16.   caret.icon   = icon;
  17.  
  18.   if (window >= 0 && icon >= 0)
  19.   {
  20.     icon_block    istate;
  21.     register char *buff;
  22.     register int  index, maxlen;
  23.  
  24.     Wimp_GetIconState(window, icon, &istate);
  25.  
  26.     if (!istate.flags.data.text || istate.flags.data.shaded)
  27.       return;          /* Not a text icon, or is shaded, so can't grab caret */
  28.  
  29.     if (istate.flags.data.indirected)
  30.     {
  31.       maxlen = istate.data.indirecttext.bufflen;
  32.       buff   = istate.data.indirecttext.buffer;
  33.     }
  34.     else
  35.     {
  36.       maxlen = 12;
  37.       buff = istate.data.text;
  38.     }
  39.  
  40.     index = 0;                                 /* Place caret at end of text */
  41.     while(index < maxlen && buff[index]>31)
  42.       index++;
  43.     caret.index = index;
  44.   }
  45.   else
  46.     caret.index = 0;
  47.  
  48.   caret.offset.y = caret.offset.x = 0;
  49.   caret.height = -1;
  50.   Wimp_SetCaretPosition(&caret);
  51. }
  52.